All Questions
Tagged with cdesign-patterns
23 questions
4votes
1answer
314views
Dealing with global variables required by badly-written library
I am working with a library that is somewhat poorly written. In order to function, it requires several global variables to be declared and sometimes even maintained by my own code. I really don't ...
1vote
0answers
90views
Mimic public/private data members in C with hidden static arrays
Context I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant. It is the ...
3votes
2answers
3kviews
Standard error codes vs custom error codes in C
I am working on improving the code quality and portability of my C library, specifically a ring buffer implementation, that will be used in larger applications. I have encountered a dilemma regarding ...
0votes
2answers
685views
How to create an interface in C that can work on two identical structs with differently named fields
Question Background Consider a scenario in which I have two structs. Both consist of three fields for doubles. The only difference is the names used to refer to these fields. The first struct is for ...
4votes
4answers
806views
Design pattern to create a shared lib architecture
I am making a renderer as a hobby, one thing I thought to try is making the low levelAPI be dynamically swappable, i.e. you could have an opengl or vulkan backend and switch between the two without ...
0votes
1answer
122views
What design pattern (if so) did I apply? How can I further improve it?
Suppose I have a program.c that needs element_123 to do some operations, and element_123 can be accessed by including agent.h /*program.c*/ #include "agent.h" uint32_t element_123 = 0; ...
0votes
0answers
80views
How to best design this communication module/library?
Introduction A customer of ours has embedded products with sensors and actuators. Now they would like to connect this device to the cloud so they can remotely monitor and configure it. It should ...
0votes
2answers
180views
Cases of memory management where it is reasonable to separate program into several execs
I have 5000+ strings pet-project for CLI and it can do some optional calculations and can output results to CLI or/and to file. Some new modules don't work. Now I catch with GDB some strange segfaults ...
2votes
1answer
61views
Architecture design for Linux administrative interface
I've developed an IoT device utilising OpenWrt so my design needs run a on a shoe-string budget of resources. I need to be able to push small amounts of data, up to 300bytes to my app on a very ...
0votes
2answers
92views
Architecture/design for reading incoming data and distributing it across program
This may be a broad question but I have not been able to find an answer. In my program I am communicating to a device over serial communication. The data coming through is binary, and formatted with ...
2votes
2answers
693views
Module pattern in C with threading - where to control threads?
So I'm working on a growing C program in a Linux / POSIX environment, and I've run into an area where I'm not quite sure how to proceed. Basically, I'm using a module pattern to develop my code for ...
9votes
3answers
551views
Writing at the start of a file something you only know at the end
Background: I'm writing micro controller C code to write an EBML file. EBML is like a binary XML with nested elements, but instead of start and end tags, there is a start ID, length, and then the data....
4votes
2answers
710views
Dynamic dispatch with captured data in C?
I'm trying to reconcile my object-oriented/functional mind with programming in a language with C. Let's say I want to achieve dynamic dispatch in C, say I want to have a collection of tasks to execute....
4votes
3answers
3kviews
Handling errors in C with "check-log-return": why not use a macro?
It's a good practice (I believe) in C to handle errors like this: int status = tree_climb(tree, ...); if (status != 0) { global_logger.message(2, "Cannot climb a tree %s", tree->name); ...
1vote
2answers
2kviews
What is the proper way to implement an abstract data type in C?
In his book Patterns in C, Adam Petersen describes using a pointer to a struct, which is declared in a header file, to create a first-class abstract data-type: /* Customer.h */ /* A pointer to an ...